package org.lanqiao.service.Impl;

import org.lanqiao.dao.TrainDao;
import org.lanqiao.dao.impl.TrainDapImpl;
import org.lanqiao.entity.Train;
import org.lanqiao.service.TrainService;

import java.util.List;

public class TrainServiceImpl implements TrainService {
    //多态
    TrainDao dao=new TrainDapImpl();
    @Override
    public boolean addTrain(Train train) {
        int row=-1;
        if (dao.isExistById(train.getId())){
            System.out.println("该数据已经存在,请勿重复操作!");
            return false;
        }else {
            row=dao.addTrain(train);
        }
        return row==1?true:false;
    }

    //修改
    @Override
    public boolean updTrain(Train train) {
        int row=-1;
        if (dao.isExistById(train.getId())){
            row=dao.updTrain(train);
        }else {
            System.out.println("该数据已经存在,请勿重复操作!");
            return false;
        }
        return row ==1?true:false;
    }

    @Override
    public boolean delTrain(Integer id) {
        int row=-1;
        if (dao.isExistById(id)){
            row=dao.delTrain(id);
        }else {
            System.out.println("该数据不存在");
            return false;
        }
        return row ==1?true:false;
    }
    //根据od查询
    @Override
    public Train findByIdTrain(Integer id) {
        return dao.findByIdTrain(id);
    }

    @Override
    public List<Train> findAllTrain() {
        return dao.findAllTrain();
    }

    @Override
    public boolean isExistByIds(Integer id) {
        return dao.isExistById(id);
    }
}
